<div class="wizard">
    <ul class="steps">
    	<?php
        	for( $i=0; $i<$setting['level']; $i++ ):
				if( $p == $i ):
    	?>
        <li id="q<?=$i?>" class="active"><span class="step"><?=$i+1;?></span><span class="title">题目 <?=$i+1;?></span><span class="chevron"></span></li>
        <?php else: ?>
        <li id="q<?=$i?>"><a href="<?=site_url('exam/main').'/'.$i;?>"><span class="step"><?=$i+1;?></span><span class="title">题目 <?=$i+1;?></span> <span class="chevron"></span></a></li>
   		<?php
        	endif;
        endfor; ?>
    </ul>
    <div class="action pull-right" style="padding-left: 10px;">
        <button type="button" class="btn btn-azure btn-lg" style="line-height: 24px; border-radius: 0; font-size: 24px;" onclick="handin()"> <i class="glyphicon glyphicon-cloud-upload" style="font-size: 24px;"></i>交卷</button>
    </div>
</div>

<form enctype="multipart/form-data" action="<?=site_url('/exam/upload')?>" method="post" onsubmit="return upload()">
<div class="well with-footer">
		<table class="table table-hover">
			<tr>
				<td colspan="2" class="bordered-bottom-3 bordered-darkorange">
					<?=$q['content']?>
				</td>
			</tr>
			<tr>
				<td>素材</td>
				<td>
					<?php
						if( empty( $q['attach'] ) ):
					?>
					无
					<?php else: ?>
					<a href="<?=base_url().$setting['q_dir'].$q['id'].'/'.$q['attach'];?>" target="_blank"><i class="fa fa-download"></i> <?=$q['attach']?></a>
					<?php endif; ?>
				</td>
			</tr>
			<tr>
				<td>上传答案</td>
				<td>
					<input type="file" name="file" id="file" value=""/>

				</td>
			</tr>
		</table>
    <div class="footer text-center">
    	<input type="hidden" name="p" value="<?=$p+1?>" />
    	<input type="submit" value="上传压缩包！" class="btn btn-lg btn-primary"/>
    </div>
</div>
</form>
<script type="text/javascript">
	/**
	 * 上传答案
	 * */
	function upload() {
		if( $("#file").val() == '' ){
			alert( '没有选择文件！' );
			return false;
		}else{
			$('form').submit();
		}
	}
	var done = eval( "<?=$done;?>" );
	set_done( done );
	function set_done( done ){
		
		console.log( done );
		for( var i=0; i<done.length; i++ ){
			if( done[i] ){
				$( '#q' + i ).addClass('complete');		
			}

		}
	}

	function handin(){
		//检查未做题目
		var undone_list = new Array();
		for( var i=0; i<done.length; i++ ){
			if( done[i] == 0 )
				undone_list.push( i + 1 );
		}
		var out = undone_list.join(',');
		if( out == '' ){
			complete_handin();
		}else{
			if( confirm( '第' + undone_list.join(',') + '题还没有上传，是否确定交卷？') ){
				complete_handin();
			}else{
				return false;
			}
		}
	}
	function complete_handin(){
		$.post( '<?=site_url('exam/handin').'/'.sess('sid');?>', function( data ){
		    data = eval( '(' + data + ')' );
		    if( data.status == 'error' ){
			    alert( data.error );
		    }else{
			    alert( data.error + '\n请安静离开考场！' );
			    window.location.href = '<?=site_url( '/')?>';
		    }
	    });
	}
</script>